Perl对默认值非常友好::jmglov@laurana;perl-e'@foo;printf"%d\n",$foo[123]'0:jmglov@laurana;perl-e'%foo;printf"%d\n",$foo{bar}'0Ruby可以做同样的事情,至少对于哈希:>>foo=Hash.new(0)=>{}>>foo[:bar]=>0但同样的方法似乎不适用于数组:>>foo=Array.new(0)=>[]>>foo[123]=>nil>>foo[124]=0=>0>>foo[456]=0=>0>>foo[455,456]=>[nil,0]是否可以为数组提供一个默认值,这样当它
选择有意义。但是有人可以向我解释.detect吗?我不明白这些数据。>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,4)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,6)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,7)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(2,7)}=>2>>[1,2,3,4,5,6,7].detect{|x|x.between?(1,7)}=>1>>[1,2,3,4,5,6,7].detect{|x